/*--------------HIEU UNG TRUOT MENU--------------------
-----------------------------------------------------*/
$(document).ready(function(){
    // menu left
    $('#sidebar ul li a').hover(function(){       
        $(this).stop().animate({left:"55px"} );
    },function(){
        $(this).stop().animate({left: "45px"});
    }
    );
    //end menu left
    
    // clode kich message
    $('.close').click(function(){
        $(this).parent('.relative').fadeOut(1000);        
    }); 
/*------------------on/off buttom------------------
---------------------------------------------------*/

    $('.box_switch').click(function(){
        var t =$(this).find('#off_on').val();
        if(t==1){
            t=0;
            $(this).addClass('off');
        }else{
            t=1;
            $(this).removeClass('off')
            } 
        $('#off_on').val(t);
        return false;
    }); 
/*-----------------confirm delete------------------
---------------------------------------------------*/
$('.del a').click(function(){
   return confirm('Are you sure?');
});
/*-----------------check all----------------------
---------------------------------------------------*/
$(".checkall").click(function()
{
    var checked_status = this.checked;
    $('input[type="checkbox"]').each(function()
    {
        this.checked = checked_status;
    });
});
/*-------------ajax kich unpublish----------------
-------------------------------------------------*/
$('.ajax').click(function(){
    var url = $(this).attr('href');
    var id = $(this).attr('id');
    var cla = $(this).attr('class');
    if(cla=='status ajax unpub'){
        url = url+'1';
    }
    $.ajax({
        type:"POST",
        url:url,
        data:{data:id},
        success:unpub,
        error:err        
    });
return false;
});
/*----------------delete--------------------------
-----------------------------------------------*/
$('.action select').change(function(){  
    var table= $(this).attr('title');
    var diachia = base_url+'admin/ajax/del_all/'+table;
    var hanhdong = $(this).val();    
    var dulieu = $('form').serializeArray(); 
    if(hanhdong=='del'&&confirm('Are you sure?')){
        $.ajax({
        type:"POST",
        url:diachia,
        data:{data:dulieu},
        success:chage_content,
        error:err        
    });
    };
});
/*------ Number field show--category chose----------
------------------------------------------------*/
$('.show_num select, .filter_cat select').change(function(){
    var diachia = $(this).attr('title');
    var num = $(this).val();
        $.ajax({
            type:"POST",
            url:diachia,
            data:{data:num},
            success:reload,
            error:err        
        });    
});
/*-------------- add class vao order--------------
------------------------------------------------*/

var selecter = '.order[title="'+order[0]+'"]';
var cla ='';
if(order[1]=='DESC'){cla='DESC';}else cla='ASC';
$(selecter).addClass(cla);
$('.order').click(function(){
    var feild=$(this).attr('title');// lay truog
    var classn = $(this).attr('class');
    if(classn == 'order'||classn=='order DESC'){
        order1='ASC';
    }else{order1 ='DESC';};    
    $.ajax({
            type:"POST",
            url:base_url+'admin/ajax/order/'+order1+'/'+feild,
            data:{data:1},
            success:reload,
            error:err        
        });
    
});

});
function unpub (data, status){
        $(data).toggleClass('unpub');
}
function reload(data, status){
    location.reload();
    //$("div .box_ajax").html(data);
}    
function err(xhr, reason, ex){
    alert('loi');
    $("div .box_ajax").html('loi');
}
function test (data, status){
        alert(data);
}
function chage_content(data, status){
    $('.box_content').html(data);
}


